import { createWebHashHistory, createRouter } from 'vue-router'
import Layout from './components/Layout.vue'

const routes = [
    { path: '/login', component: () => import('./views/Login.vue') },
    {
        path: '/',
        component: Layout,
        children: [
            { path: 'home', component: () => import('./views/Home.vue'), meta: { showBack: false, title: 'Order System-Merchant' } },
            { path: 'order', component: () => import('./views/order/index.vue'), meta: { showBack: true, title: 'Order Management' } },
            { path: 'user', component: () => import('./views/user/index.vue'), meta: { showBack: true, title: 'User Management' } },
            { path: 'tongji', component: () => import('./views/tongji/index.vue'), meta: { showBack: true, title: 'Statistics Management' } },
            { path: 'use', component: () => import('./views/use/index.vue'), meta: { showBack: true, title: 'Usage Statistics' } },
            { path: 'menu', component: () => import('./views/menu/index.vue'), meta: { showBack: true, title: 'Menu Management' } },
            { path: 'feedback', component: () => import('./views/feedback/index.vue'), meta: { showBack: true, title: 'Feedback Management' } },
            { path: 'language', component: () => import('./views/language/index.vue'), meta: { showBack: true, title: 'Language Management' } },
            { path: 'settings', component: () => import('./views/settings/index.vue'), meta: { showBack: true, title: 'Settings' } }
        ]
    }
]
const router = createRouter({ history: createWebHashHistory(), routes })

router.beforeEach((to, from, next) => {
    if (to.path === '/') {
        next('/home')
    } else {
        next()
    }
})

export default router